import django_filters
from django.contrib.auth import get_user_model

from apps.vadmin.assets.models.check_records import CheckRecords 
from apps.vadmin.assets.models.components_assets import Components_Assets 
from apps.vadmin.assets.models.accessories_users import Accessories_Users
from apps.vadmin.assets.models.consumables_users import Consumables_Users 
from apps.vadmin.assets.models.license_seats import License_Seats
from apps.vadmin.assets.models.categories import Categories
from apps.vadmin.assets.models.accessories import Accessories
from apps.vadmin.assets.models.assets import Assets
from apps.vadmin.assets.models.locations import Locations
from apps.vadmin.assets.models.components import Components
from apps.vadmin.assets.models.consumables import Consumables
from apps.vadmin.assets.models.depreciations import Depreciations
from apps.vadmin.assets.models.kits import Kits
from apps.vadmin.assets.models.licenses import Licenses
from apps.vadmin.assets.models.maintenances import Maintenances
from apps.vadmin.assets.models.manufacturers import Manufacturers
from apps.vadmin.assets.models.models import Models
from apps.vadmin.assets.models.report import CategoryTotalReport, UserCheckoutReport
from apps.vadmin.assets.models.suppliers import Suppliers
from apps.vadmin.assets.models.uploads import Uploads
from apps.vadmin.assets.models.report import AssetNowCheckoutReport


UserProfile = get_user_model()


class CategoriesFilter(django_filters.rest_framework.FilterSet):
    """
    资产分类管理 简单序过滤器
    """
    name = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Categories
        exclude = ('description', 'creator', 'modifier','eula_text','image')


class ModelsFilter(django_filters.rest_framework.FilterSet):
    """
    型号管理 简单序过滤器
    """
    name = django_filters.CharFilter(lookup_expr='icontains')
    model_number = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Models
        exclude = ('description', 'creator', 'modifier','image','notes')


class SuppliersFilter(django_filters.rest_framework.FilterSet):
    """
    供应商管理 简单序过滤器
    """
    name = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Suppliers
        exclude = ('description', 'creator', 'modifier','image')


class ManufacturersFilter(django_filters.rest_framework.FilterSet):
    """
    制造商管理 简单序过滤器
    """
    name = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Manufacturers
        exclude = ('description', 'creator', 'modifier','image')


class DepreciationsFilter(django_filters.rest_framework.FilterSet):
    """
    折旧管理 简单序过滤器
    """
    name = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Depreciations
        exclude = ('description', 'creator', 'modifier')

class AssetsFilter(django_filters.rest_framework.FilterSet):
    """
    资产管理 简单序过滤器
    """
    name = django_filters.CharFilter(lookup_expr='icontains')
    serial = django_filters.CharFilter(lookup_expr='icontains')
    order_number = django_filters.CharFilter(lookup_expr='icontains')
    asset_tag = django_filters.CharFilter(lookup_expr='icontains')
    requestable = django_filters.BooleanFilter(exclude=True)
    byod = django_filters.BooleanFilter()
    assigned_null = django_filters.BooleanFilter(field_name='assigned_to_id', lookup_expr='isnull')
    deleted = django_filters.BooleanFilter(field_name='deleted_datetime', lookup_expr='isnull',exclude=True)
    audit_date_lt = django_filters.DateTimeFilter(field_name='next_audit_date', lookup_expr='lt')
    audit_date_eq = django_filters.DateTimeFilter(field_name='next_audit_date', lookup_expr='exact')

    class Meta:
        model = Assets 
        exclude = ('description', 'creator', 'modifier','notes','image')
        fields = ['id','status','assigned_null','deleted','audit_date_lt','audit_date_eq','assigned_type','assigned_to_id','creator_id','expected_checkin','depreciate','physical']

class AccessoriesFilter(django_filters.rest_framework.FilterSet):
    """
    附属品、配件管理 简单序过滤器
    """
    name = django_filters.CharFilter(lookup_expr='icontains')
    order_number = django_filters.CharFilter(lookup_expr='icontains')
    model_number = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Accessories 
        exclude = ('description', 'creator', 'modifier','notes','image')


class ComponentsFilter(django_filters.rest_framework.FilterSet):
    """
    资产组件管理 简单序过滤器
    """
    name = django_filters.CharFilter(lookup_expr='icontains')
    serial = django_filters.CharFilter(lookup_expr='icontains')
    order_number = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Components 
        exclude = ('description', 'creator', 'modifier','notes','image')


class ConsumablesFilter(django_filters.rest_framework.FilterSet):
    """
    消耗品管理 简单序过滤器
    """
    name = django_filters.CharFilter(lookup_expr='icontains')
    item_no = django_filters.CharFilter(lookup_expr='icontains')
    order_number = django_filters.CharFilter(lookup_expr='icontains')
    model_number = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Consumables 
        exclude = ('description', 'creator', 'modifier','notes','image')

        
class LicensesFilter(django_filters.rest_framework.FilterSet):
    """
    软件许可管理 简单序过滤器
    """
    name = django_filters.CharFilter(lookup_expr='icontains')
    serial = django_filters.CharFilter(lookup_expr='icontains')
    license_name = django_filters.CharFilter(lookup_expr='icontains')
    license_email = django_filters.CharFilter(lookup_expr='icontains')
    order_number = django_filters.CharFilter(lookup_expr='icontains')
    purchase_order = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Licenses 
        exclude = ('description', 'creator', 'modifier','notes')


class KitsFilter(django_filters.rest_framework.FilterSet):
    """
    资产套件管理 简单序过滤器
    """
    name = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Kits 
        exclude = ('description', 'creator', 'modifier')

class MaintenancesFilter(django_filters.rest_framework.FilterSet):
    """
    资产维护过滤器
    """
    title = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model =  Maintenances
        exclude = ('description', 'creator', 'modifier')

class UploadsFilter(django_filters.rest_framework.FilterSet):
    """
    上传文件过滤器
    """
    filename = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Uploads
        exclude = ('description', 'creator', 'modifier')

class LocationsFilter(django_filters.rest_framework.FilterSet):
    """
    地理位置过滤器
    """
    name = django_filters.CharFilter(lookup_expr='icontains')
    address = django_filters.CharFilter(lookup_expr='icontains')
    address2 = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Locations 
        exclude = ('description', 'creator', 'modifier')

class UserCheckoutReportFilter(django_filters.rest_framework.FilterSet):
    """
    用户资产统计报表过滤器
    """

    class Meta:
        model = UserCheckoutReport
        fields = '__all__' 


class CategoryTotalReportFilter(django_filters.rest_framework.FilterSet):
    """
    分类统计报表过滤器
    """

    class Meta:
        model = CategoryTotalReport
        fields = '__all__' 

class CheckRecordsFilter(django_filters.rest_framework.FilterSet):
    """
    借出归还记录过滤器
    """
    check_name = django_filters.CharFilter(lookup_expr='icontains')
    assigned_to_name = django_filters.CharFilter(lookup_expr='icontains')
    notes = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = CheckRecords 
        fields = '__all__' 

class ComponentsAssetsFilter(django_filters.rest_framework.FilterSet):
    class Meta:
        model = Components_Assets
        fields = '__all__' 

class AccessoriesUsersFilter(django_filters.rest_framework.FilterSet):
    class Meta:
        model = Accessories_Users
        fields = '__all__' 

class ConsumablesUsersFilter(django_filters.rest_framework.FilterSet):
    class Meta:
        model = Consumables_Users
        fields = '__all__' 

class LicenseSeatsFilter(django_filters.rest_framework.FilterSet):
    class Meta:
        model = License_Seats
        fields = '__all__' 

class AssetNowCheckoutReportFilter(django_filters.rest_framework.FilterSet):
    class Meta:
        model = AssetNowCheckoutReport 
        fields = '__all__' 
